#include "utils.h"

QString GetString(QJsonObject &data, QString key) {
    if (data.contains(key)) {
        return data[key].toString();
    }
    return "";
}

int GetInt(QJsonObject &data, QString key) {
    if (data.contains(key)) {
        return data[key].toInt();
    }
    return 0;
}

bool GetBool(QJsonObject &data, QString key){
    if (data.contains(key)) {
        return data[key].toBool();
    }
    return false;
}

QString GetValidityCountString(int DateUnit, int DateCount){
    switch (DateUnit) {
    case SVT_HOUR:
        return QString("%1小时").arg(DateCount);
    case SVT_DATE:
        return QString("%1天").arg(DateCount);
    case SVT_WEEK:
        return "周末打烊";
    case SVT_MOUNTH:
        return QString("%1月").arg(DateCount);
    case SVT_CLOSE:
        return "当日打烊";
    case SVT_PRIORITY:
        return "下次优先使用";
    default:
        return "无";
    }
}

QString GetSaveTypeString(int SaveType){
    switch(SaveType) {
    case 1:
        return "冷冻";
    case 2:
        return "冷藏";
    case 3:
        return "常温";
    case 10:
        return "其它";
    default:
        return "未知";
    }
}

QString GetOperationTypeString(int OperationType){
    switch(OperationType) {
    case 1:
        return "解冻";
    case 2:
        return "开封";
    case 3:
        return "煮制";
    case 4:
        return "调制";
    case 5:
        return "装瓶";
    case 6:
        return "分装";
    case 7:
        return "切配";
    case 10:
        return "其它";
    default:
        return "未知";
    }
}
